//
//  WJBaseView.m
//  WJBSApp
//
//  Created by dllo on 16/7/13.
//  Copyright © 2016年 王景伟. All rights reserved.
//

#import "WJBaseView.h"

@interface WJBaseView ()

@property (nonatomic,retain) UILabel *lable;

@end


@implementation WJBaseView

-(void)dealloc{
    [_lable release];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

// 创建6个图片的方法
-(instancetype)initWithFrame:(CGRect)frame imageName:(NSString *)imageName name:(NSString *)name
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.width)];
        image.image = [UIImage imageNamed:imageName];
        [self addSubview:image];
        [image release];
        
        _lable = [[UILabel alloc]initWithFrame:CGRectMake(0,self.bounds.size.width, self.bounds.size.width, self.bounds.size.height - self.bounds.size.width)];
        [self addSubview:_lable];
        _lable.text = name;
        _lable.textAlignment = 1;
        [_lable release];
        
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
            _lable.textColor = [UIColor whiteColor];
        }else{
            _lable.textColor = [UIColor blackColor];
        }
        // 创建观察者
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
         
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
            self.backgroundColor = FIRBLACKCOLOR;
            
        }else{
            self.backgroundColor = LABLECOLOR;

        }
        // 创建观察者
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor1:) name:@"changeColor" object:nil];
        
    }
    return self;
}
- (void)changeColor:(NSNotification *)cation
{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
        
        _lable.textColor = [UIColor whiteColor];
    }else{
        _lable.textColor = [UIColor blackColor];
    }
}
- (void)changeColor1:(NSNotification *)cation
{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
        self.backgroundColor = FIRBLACKCOLOR;
        
    }else{
        self.backgroundColor = LABLECOLOR;
        
    }
}







@end
